package com.hy.memoryassistant;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;

import java.util.List;

/**
 * Created by Mike on 01/02/2015.
 */
public class NotificationHelper {
    private Context mContext;

    public NotificationHelper(Context context) {
        mContext = context;
    }

    public void showReminder(Reminder reminder) {
        Notification.Builder mBuilder = new Notification.Builder(mContext).setSmallIcon(R.drawable.ic_action_about).setContentTitle(reminder.title);

        Intent resultIntent = new Intent(mContext, NoteDetailActivity.class);

        // pass in the reminder ID here
        resultIntent.putExtra(NoteDetailFragment.ARG_ITEM_ID, reminder.ID);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        stackBuilder.addParentStack(NoteDetailActivity.class);

        stackBuilder.addNextIntent(resultIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        // mId allows you to update the notification later on.
        mNotificationManager.notify(0, mBuilder.build());
    }

    public void showReminders(List<Reminder> reminders) {
        Notification.Builder mBuilder =
                new Notification.Builder(mContext)
                        .setSmallIcon(R.drawable.ic_action_about)
                        .setContentTitle("Today's Reminders");

        Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
        inboxStyle.setBigContentTitle("Today's Reminders");

        for (Reminder r : reminders) {
            inboxStyle.addLine(r.title);
        }

        mBuilder.setStyle(inboxStyle);

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(mContext, NoteListActivity.class);
        // for individual notifications, disable the following code
        //resultIntent.putExtra(NoteDetailFragment.ARG_ITEM_ID, new Long(1));

        // The stack builder object will contain an artificial back stack for the
        // started Activity.
        // This ensures that navigating backward from the Activity leads out of
        // your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(NoteListActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        // mId allows you to update the notification later on.
        mNotificationManager.notify(0, mBuilder.build());
    }


}
